﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.DirectX;
using System.Reflection;

namespace RayTracerLib.Common
{
    public static class Utilities
    {
        public static float GetValueByIndex(Matrix m, int i, int j)
        {
            FieldInfo[] fields = m.GetType().GetFields();
            foreach (FieldInfo field in fields)
            {
                if (field.Name.Length > 2 && string.Compare(field.Name[1].ToString(), (i + 1).ToString()) == 0
                    && string.Compare(field.Name[2].ToString(), (j + 1).ToString()) == 0)
                    return (float)field.GetValue(m);
            }
            return 0;
        }
        public static void SetValueByIndex(ref Matrix m, int i, int j, float value)
        {
            FieldInfo[] fields =  m.GetType().GetFields();            
            foreach (FieldInfo field in fields)
            {
                if (field.Name.Length > 2 && string.Compare(field.Name[1].ToString(), (i + 1).ToString()) == 0
                    && string.Compare(field.Name[2].ToString(), (j + 1).ToString()) == 0)
                {
                    field.SetValueDirect(__makeref(m), value);                       
                    break;
            }
            }
        }
    }
}
